Repository navigation
fix(presets): tolerate trailing whitespace on command frontmatter fences - #5660
Merged
mnriem merged 1 commit intoDec 2, 2026
Conversation
PresetResolver recognised a command file's frontmatter only when the
delimiter lines were exactly ``---``. A stray space or tab after the
closing line meant _split_frontmatter never saw the end of the block,
so a preset's YAML (description, strategy) was appended to the composed
command body, and the legacy frontmatter strategy lookup kept the
default "replace". The opening line had the same exact-match rule and
the same failure.
Both delimiters are now matched with one predicate: ``---`` on its own
line, trailing whitespace ignored. That is the rule
CommandRegistrar.parse_frontmatter already applies to the closing line.
Leading whitespace is still rejected because an indented ``---`` can be
scalar content. The rstrip("\r\n") on the reattached block only trims
its line terminator and is unchanged.
Assisted-by: ZCode (model: GLM-5.4, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change centralizes whitespace-tolerant fence handling across preset resolution and command composition and includes regression coverage for newline formats, legacy lookup, and invalid delimiters, with no active issues identified.
No open issues 🎉
What changed in this PR
This pull request makes preset command frontmatter fences tolerate trailing whitespace while preserving strict delimiter matching, preventing metadata leakage and restoring legacy strategy detection.
Changes:
- Adds a shared fence predicate for preset resolution and command composition.
- Adds regression coverage for whitespace, LF/CRLF input, legacy strategy lookup, and invalid fence variants.
- The CRLF fixture should write content without platform newline translation so it reliably tests Windows behavior.
| File | Description |
|---|---|
| tests/specify_cli/presets/test_resolver.py | Adds regression tests for whitespace-tolerant frontmatter fences, LF/CRLF input, legacy strategy handling, and invalid delimiter variants. |
| src/specify_cli/presets/_resolver.py | Centralizes tolerant frontmatter fence detection and applies it to preset strategy lookup and command composition. |
Review effort: Lite (adaptive)
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PresetResolverstrips the YAML frontmatter off each command file before composing a preset over a core command, so that only the top layer's metadata goes back into the result. It recognised the---lines only when they were exactly---. With one stray space or tab after the closing line (easy to pick up when editing by hand) the block was never seen as closed, and the preset'sdescription:/strategy:lines were appended to the composed command body. The same line also hid astrategy:in the command file from the legacy lookup (nostrategyinpreset.yml), which then stayed atreplaceand dropped the core command's content. The opening line had the same exact-match rule and the same failure.All four delimiter checks in
_resolver.pynow share one predicate:---on its own line, trailing whitespace ignored. That is the ruleCommandRegistrar.parse_frontmatterinagents.pyalready applies to the closing line, and the same tolerance #5609 brought toreplace-section. Leading whitespace is still rejected (an indented---can be scalar content), so lines such as----,--- textor---are not delimiters.Testing
Set up this checkout's
.venvand editable install using the local development guide. Run commands from the checkout root..venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help) — not run by a human; the agent ran.venv/bin/specify --help(exit 0).venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOS — not run by a human; the agent ran the automated tests listed belowAutomated checks run by the agent on this branch:
tests/specify_cli/presets/test_resolver.py, 17 rows in total. The two positive tests (composed command, legacy strategy) have four rows each — a space or a tab after the closing or the opening line — and the composed-command test runs with both LF and CRLF files. Onmain(397d9d1) the 12 positive rows fail:strategy: appendis found in the composed body, andlayers[0]["strategy"]isreplaceinstead ofappend. With this change all 17 pass.----,--- textand an indented---as closing line, and----and an indented---as opening line. They pass onmaintoo (the layer is appended unchanged) and fail if the rule is widened to a prefix or a strip match.tests/specify_cli/presets/test_resolver.py: 121 passed.tests/specify_cli/presets/: 886 passed, 1 skipped.PresetResolver,resolve_content,collect_all_layersorparse_frontmatter: 1188 passed, 91 skipped.LC_ALL=en_US.UTF-8 .venv/bin/python -m pytest tests -q -p no:cacheprovider): 17622 passed, 665 skipped.uvx ruff@0.15.0 check src testsandgit diff --check: clean.uvx ruff@0.15.0 format --checkreports both changed files, as it already does onmain(16 and 66 hunks, the same before and after); none of the added lines is inside a hunk. Repository pre-commit hooks on the changed files:end-of-file-fixerandtrailing-whitespacepassed, two hooks skipped as not applicable.AI Disclosure
AI disclosure: Implemented with ZCode (an agent driven by GLM-5.4, reasoning effort max) in autonomous mode on behalf of the account holder. Extent: code generation — the agent found the bug by reading the code, wrote the fix and the regression tests, and ran the automated tests listed above; no docs changes. No human reviewed the code or ran manual tests before this pull request was submitted.